﻿using System;
using EzDesk.Core.ServiceImpl.Services;
using NUnit.Framework;

namespace EzDesk.Core.UnitTest
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestFixture]
    public class TokenServiceFixture
    {
        public TokenServiceFixture()
        {
            _clientTokenPool = ClientTokenPool.Instance;
        }

        private ClientTokenPool _clientTokenPool;

        
        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [Test]
        public void Test_RequestToken()
        {
            Guid userId = Guid.NewGuid();

            string token = _clientTokenPool.RequestToken(userId);

            Assert.IsNotNull(userId);
        }

        [Test]
        public void Test_RequestToken_Cache_Function()
        {
            Guid userId = Guid.NewGuid();
            string expected = _clientTokenPool.RequestToken(userId);

            string actual = _clientTokenPool.RequestToken(userId);

            Assert.AreEqual(expected, actual);  
        }
        [Test]
        public void Test_GetUserIdByToken()
        {
            Guid userId = Guid.NewGuid();
            string token = _clientTokenPool.RequestToken(userId);

            Guid actualUserId = _clientTokenPool.GetUserIdByToken(token);

            //Assert.AreSame(userId,actualUserId);
            Assert.AreEqual(userId, actualUserId);
        }

    }
}
